﻿<div id="createDialog" class="crudDialog">
    <form id="createForm" method="post">
        <div class="form-group">
            <span>
				<select id="roleId"  name="roleId">
					<option th:each="role:${roles}" th:value="${role.id}" th:text="${role.roleName}"></option>
				</select>
			</span>
        </div>
        <div class="form-group">
            <label for="name">账号</label>
            <input id="name" type="text" class="form-control" name="adminName" maxlength="20">
        </div>
        <div class="form-group  " >
            <label for="password">密码</label>
            <input id="password" type="text" class="form-control" name="password" maxlength="50">
        </div>
        <div class="form-group " >
            <label for="newpwd">重复密码</label>
            <input id="newpwd" type="text" class="form-control" name="pass" maxlength="50">
        </div>
        <div class="form-group " >
            <label for="desc">账号描述</label>
            <input id="desc" type="text" class="form-control" name="adminDesc" maxlength="50">
        </div>

        <div class="form-group text-right dialog-buttons">
            <a class="waves-effect waves-button" href="javascript:;" onclick="createSubmit();">保存</a>
            <a class="waves-effect waves-button" href="javascript:;" onclick="createDialog.close();">取消</a>
        </div>
    </form>
</div>
<script>
    function createSubmit() {
        $.ajax({
            type: 'post',
            url: 'create',
            data: $('#createForm').serialize(),
            beforeSend: function () {
                if ($('#name').val() == '') {
                    $('#name').focus();
                    return false;
                }
                if ($('#password').val() == '') {
                    $('#password').focus();
                    return false;
                }
                if ($('#desc').val() == '') {
                    $('#desc').focus();
                    return false;
                }
                if ($('#password').val() != $('#newpwd').val()) {
                    $.alert("两次密码不一样!");
                    return false;
                }
            },
            success: function (result) {
                if (result.code != 0) {
                    $.confirm({
                        theme: 'dark',
                        animation: 'rotateX',
                        closeAnimation: 'rotateX',
                        title: false,
                        content: result.errMsg,
                        buttons: {
                            confirm: {
                                text: '确认',
                                btnClass: 'waves-effect waves-button waves-light'
                            }
                        }
                    });
                } else {
                    createDialog.close();
                    $table.bootstrapTable('refresh');
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.confirm({
                    theme: 'dark',
                    animation: 'rotateX',
                    closeAnimation: 'rotateX',
                    title: false,
                    content: textStatus,
                    buttons: {
                        confirm: {
                            text: '确认',
                            btnClass: 'waves-effect waves-button waves-light'
                        }
                    }
                });
            }
        });
    }
</script>